import java.util.HashMap;
import java.util.Iterator;

/**
 * Created by WEN on 2016/10/8.
 */
public class LongestPalindrome {
    public int longestPalindrome(String s) {
        HashMap<Character,Integer> hm = new HashMap<Character, Integer>();
        Integer value;
        int sum=0;
        Boolean flag=false;
        for(int i=0; i<s.length(); i++){
            value = hm.get(s.charAt(i));
            if(value==null){
                hm.put(s.charAt(i),1);
            }else hm.put(s.charAt(i),value+1);
        }
        Iterator<Character> it = hm.keySet().iterator();
        while (it.hasNext()){
            value = hm.get(it.next());
            if(value%2==0){
                sum+=value;
            }else{
                sum=sum+value-1;
                flag=true;
            }
        }
        if(flag) sum++;
        return sum;
    }
}
